/*
 * 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙，邂逅框架梦]
 * 
 * https://zhiqim.org/project/zhiqim_framework/zhiqim_orm.htm
 *
 * Zhiqim ORM is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */
package org.zhiqim.orm.dbo.condition;

import org.zhiqim.kernel.model.maps.MapSO;
import org.zhiqim.orm.ORMException;
import org.zhiqim.orm.dbo.Condition;
import org.zhiqim.orm.dbo.Dbo;


/**
 * 比较类型的条件，一共支持6种
 * 
 * @see _Equal      相等
 * @see _EqualNot   不等
 * @see _ThenG      大于
 * @see _ThenGE     大于等于
 * @see _ThenL      小于
 * @see _ThenLE     小于等于
 * @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
 */
public abstract class _Compare extends Condition
{
    protected String field;
    protected Object value;
    protected String compare;
    
    public _Compare(String field, Object value, String compare)
    {
        this.field = field;
        this.value = value;
        this.compare = compare;
    }
    
    public String toSql(Dbo dbo, MapSO paramMap) throws ORMException
    {
        assertField(dbo, field);
        
        String column = dbo.getColumn(field);

        int ind = paramMap.size();
        paramMap.put(field+ind, convertValue(value));//把值放到表中，后续方便把##转成?号，然后再设置值
        
        return new StringBuilder()
            .append(column).append(_SPACE_).append(compare).append(_SPACE_)
            .append("#").append(field+ind).append("#")
            .toString();
    }
    
    public String getField()
    {
        return field;
    }
    
    public Object getValue()
    {
        return value;
    }
}
